🎖️GitЯра🎖️
Node / meshtastic / Meshtastic-Android / files / desktopApp / src / test / kotlin / org / meshtastic / desktop / notification / LinuxNotificationSenderTest.kt
Displaying Raw • Download
desktopApp/src/test/kotlin/org/meshtastic/desktop/notification/LinuxNotificationSenderTest.kt bd2863243bab6eb213401d949839a2bc74dde7e2 (bd286324) Text, 4.24 KB
T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.desktop.notification
Tff7b72import T7ee787org.meshtastic.core.repository.Notification
Tff7b72import T7ee787kotlin.test.Test
Tff7b72import T7ee787kotlin.test.assertFalse
Tff7b72import T7ee787kotlin.test.assertTrue
T8b949e/**
* Tests for [LinuxNotificationSender].
*
* These are integration-ish tests that verify the JNA-based sender can be instantiated. On CI or environments without
* libnotify, the sender gracefully reports [LinuxNotificationSender.isAvailable] = false and `send()` returns false. On
* a Linux dev machine with libnotify installed, these tests will actually display notifications.
*/
Tff7b72class T56d364LinuxNotificationSenderTest Tb4b4b4{
Tff7b72private Tff7b72val Te6edf3sender Tff7b72= Te6edf3LinuxNotificationSenderTb4b4b4(Te6edf3appName Tff7b72= Ta5d6ff"Ta5d6ffMeshtasticTestTa5d6ff"Tb4b4b4)
Tf0883e@Test
Tff7b72fun Td2a8ff`sender initializes without crashing`Tb4b4b4(Tb4b4b4) Tb4b4b4{
T8b949e// Just verifying construction doesn't throw — isAvailable depends on the host having libnotify
T8b949e// This is a smoke test; the actual JNA call is validated by the availability check
Tf0883e@SuppressTb4b4b4(Ta5d6ff"Ta5d6ffktlint:standard:backing-property-namingTa5d6ff"Tb4b4b4)
Tff7b72val Te6edf3available Tff7b72= Te6edf3senderTb4b4b4.Te6edf3isAvailable
Te6edf3availableTb4b4b4.Te6edf3toStringTb4b4b4(Tb4b4b4) T8b949e// use the val to satisfy lint
Tb4b4b4}
Tf0883e@Test
Tff7b72fun Td2a8ff`send returns false when libnotify unavailable`Tb4b4b4(Tb4b4b4) Tb4b4b4{
Tff7b72if Tb4b4b4(Te6edf3senderTb4b4b4.Te6edf3isAvailableTb4b4b4) Tff7b72return T8b949e// skip on systems with libnotify — would actually show a notification
Tff7b72val Te6edf3result Tff7b72= Te6edf3senderTb4b4b4.Te6edf3sendTb4b4b4(Te6edf3NotificationTb4b4b4(Te6edf3title Tff7b72= Ta5d6ff"Ta5d6ffTestTa5d6ff"Tb4b4b4, Te6edf3message Tff7b72= Ta5d6ff"Ta5d6ffHelloTa5d6ff"Tb4b4b4)Tb4b4b4)
Te6edf3assertTrueTb4b4b4(Tff7b72!Te6edf3resultTb4b4b4, Ta5d6ff"Ta5d6ffExpected send() to return false when libnotify is not availableTa5d6ff"Tb4b4b4)
Tb4b4b4}
Tf0883e@Test
Tff7b72fun Td2a8ff`send with all notification types does not crash`Tb4b4b4(Tb4b4b4) Tb4b4b4{
Tff7b72if Tb4b4b4(Tff7b72!Te6edf3senderTb4b4b4.Te6edf3isAvailableTb4b4b4) Tff7b72return T8b949e// skip on systems without libnotify
Tff7b72for Tb4b4b4(Te6edf3type Tff7b72in Te6edf3NotificationTb4b4b4.Te6edf3TypeTb4b4b4.Te6edf3entriesTb4b4b4) Tb4b4b4{
Tff7b72val Te6edf3result Tff7b72= Te6edf3senderTb4b4b4.Te6edf3sendTb4b4b4(Te6edf3NotificationTb4b4b4(Te6edf3title Tff7b72= Ta5d6ff"Ta5d6ffType: Tffd700$Te6edf3typeTa5d6ff"Tb4b4b4, Te6edf3message Tff7b72= Ta5d6ff"Ta5d6ffTesting Tffd700$Te6edf3typeTa5d6ff"Tb4b4b4, Te6edf3type Tff7b72= Te6edf3typeTb4b4b4)Tb4b4b4)
Te6edf3assertTrueTb4b4b4(Te6edf3resultTb4b4b4, Ta5d6ff"Ta5d6ffExpected send() to succeed for type Tffd700$Te6edf3typeTa5d6ff"Tb4b4b4)
Tb4b4b4}
Tb4b4b4}
Tf0883e@Test
Tff7b72fun Td2a8ff`send with all categories does not crash`Tb4b4b4(Tb4b4b4) Tb4b4b4{
Tff7b72if Tb4b4b4(Tff7b72!Te6edf3senderTb4b4b4.Te6edf3isAvailableTb4b4b4) Tff7b72return T8b949e// skip on systems without libnotify
Tff7b72for Tb4b4b4(Te6edf3category Tff7b72in Te6edf3NotificationTb4b4b4.Te6edf3CategoryTb4b4b4.Te6edf3entriesTb4b4b4) Tb4b4b4{
Tff7b72val Te6edf3result Tff7b72=
Te6edf3senderTb4b4b4.Te6edf3sendTb4b4b4(Te6edf3NotificationTb4b4b4(Te6edf3title Tff7b72= Ta5d6ff"Ta5d6ffCat: Tffd700$Te6edf3categoryTa5d6ff"Tb4b4b4, Te6edf3message Tff7b72= Ta5d6ff"Ta5d6ffTesting Tffd700$Te6edf3categoryTa5d6ff"Tb4b4b4, Te6edf3category Tff7b72= Te6edf3categoryTb4b4b4)Tb4b4b4)
Te6edf3assertTrueTb4b4b4(Te6edf3resultTb4b4b4, Ta5d6ff"Ta5d6ffExpected send() to succeed for category Tffd700$Te6edf3categoryTa5d6ff"Tb4b4b4)
Tb4b4b4}
Tb4b4b4}
Tf0883e@Test
Tff7b72fun Td2a8ff`silent notification does not crash`Tb4b4b4(Tb4b4b4) Tb4b4b4{
Tff7b72if Tb4b4b4(Tff7b72!Te6edf3senderTb4b4b4.Te6edf3isAvailableTb4b4b4) Tff7b72return
Tff7b72val Te6edf3result Tff7b72= Te6edf3senderTb4b4b4.Te6edf3sendTb4b4b4(Te6edf3NotificationTb4b4b4(Te6edf3title Tff7b72= Ta5d6ff"Ta5d6ffSilentTa5d6ff"Tb4b4b4, Te6edf3message Tff7b72= Ta5d6ff"Ta5d6ffShhhTa5d6ff"Tb4b4b4, Te6edf3isSilent Tff7b72= Tff7b72trueTb4b4b4)Tb4b4b4)
Te6edf3assertTrueTb4b4b4(Te6edf3resultTb4b4b4, Ta5d6ff"Ta5d6ffExpected silent send() to succeedTa5d6ff"Tb4b4b4)
Tb4b4b4}
Tf0883e@Test
Tff7b72fun Td2a8ff`close is idempotent`Tb4b4b4(Tb4b4b4) Tb4b4b4{
T8b949e// Uses its own sender: close() calls notify_uninit(), which tears down libnotify for the whole process.
T8b949e// Every other test builds its own sender and so re-runs notify_init().
Tff7b72val Te6edf3closeable Tff7b72= Te6edf3LinuxNotificationSenderTb4b4b4(Te6edf3appName Tff7b72= Ta5d6ff"Ta5d6ffMeshtasticTestCloseTa5d6ff"Tb4b4b4)
Te6edf3closeableTb4b4b4.Te6edf3closeTb4b4b4(Tb4b4b4)
Te6edf3closeableTb4b4b4.Te6edf3closeTb4b4b4(Tb4b4b4) T8b949e// second call must be a no-op, not a double notify_uninit()
Te6edf3assertFalseTb4b4b4(Te6edf3closeableTb4b4b4.Te6edf3isAvailableTb4b4b4, Ta5d6ff"Ta5d6ffExpected isAvailable to be false after close()Ta5d6ff"Tb4b4b4)
Tb4b4b4}
Tf0883e@Test
Tff7b72fun Td2a8ff`send after close returns false instead of calling into a torn-down library`Tb4b4b4(Tb4b4b4) Tb4b4b4{
Tff7b72val Te6edf3closeable Tff7b72= Te6edf3LinuxNotificationSenderTb4b4b4(Te6edf3appName Tff7b72= Ta5d6ff"Ta5d6ffMeshtasticTestClosedSendTa5d6ff"Tb4b4b4)
Te6edf3closeableTb4b4b4.Te6edf3closeTb4b4b4(Tb4b4b4)
Tff7b72val Te6edf3result Tff7b72= Te6edf3closeableTb4b4b4.Te6edf3sendTb4b4b4(Te6edf3NotificationTb4b4b4(Te6edf3title Tff7b72= Ta5d6ff"Ta5d6ffAfter closeTa5d6ff"Tb4b4b4, Te6edf3message Tff7b72= Ta5d6ff"Ta5d6ffShould not be deliveredTa5d6ff"Tb4b4b4)Tb4b4b4)
Te6edf3assertFalseTb4b4b4(Te6edf3resultTb4b4b4, Ta5d6ff"Ta5d6ffExpected send() to return false after close()Ta5d6ff"Tb4b4b4)
Tb4b4b4}
Tb4b4b4}
Served by rngit 1.5.0 - Generated in 0.05s